fun main() {
    val dataList = listOf(24, 18, 12, 9, 16, 66, 32, 4)
    val result = LinearSearch.search(dataList, 16)
    println(result)

    val studentList = listOf(Person("mike"), Person("bobby"))
    val student = Person("bobby")
    val searchStudent = LinearSearch.search(studentList, student)
    print(searchStudent)
}


object LinearSearch {
    fun <E> search(data: List<E>, target: E): Int {
        data.forEachIndexed { index, i ->
            if (i == target) {
                return index
            }
        }
        return -1
    }
}

class Person(val name: String) {
    override fun equals(other: Any?): Boolean {
        return this === other || other is Person && this.name == other.name
    }

    override fun hashCode(): Int {
        return name.hashCode()
    }
}